import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'dart:io';

class ImagePickerWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ImagePickerState();
  }
}

class _ImagePickerState extends State<ImagePickerWidget> {
  File _image;

  Future getImageCamera() async {
    var image = await ImagePicker.pickImage(source: ImageSource.camera);
    setState(() {
      _image = image;
    });
  }
  Future getImageGallery() async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);
    setState(() {
      _image = image;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('信息录入'),
        centerTitle: true,
        actions: <Widget>[
            IconButton(
              icon: Icon(IconData(0xe645, fontFamily: "Iconfont"), size: 24.0),
              tooltip: "保存",
              onPressed: () {},
            ),
        ]
      ),
      body: SingleChildScrollView(
          child: Column(
              children: <Widget>[
                Container(
                    height: ScreenUtil().setHeight(300),
                    width: double.infinity,
                    margin: EdgeInsets.all(10),
                    decoration: BoxDecoration(
                        border: Border.all(color: Colors.grey, width: 1.0),
                        borderRadius: BorderRadius.circular(3.0)
                    ),
                    child: _image == null
                            ? Center(child: Text('请拍照'),)
                            : Image.file(_image,fit: BoxFit.fill),
                ),
                Row(
                    children: <Widget>[
                        Expanded(
                            child: Container(
                                width: double.infinity,
                                height: ScreenUtil().setHeight(80),
                                margin: EdgeInsets.all(20.0),
                                child: FlatButton(
                                    color: Color.fromRGBO(81, 126, 219, 1),
                                    shape:RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
                                    child: Text(
                                        "拍摄证件",
                                        style: TextStyle(color: Colors.white),
                                    ),
                                    onPressed: getImageCamera,
                                )
                            ),
                        ),
                        Expanded(
                            child: Container(
                                width: double.infinity,
                                height: ScreenUtil().setHeight(80),
                                margin: EdgeInsets.all(20.0),
                                child: FlatButton(
                                    color: Color.fromRGBO(81, 126, 219, 1),
                                    shape:RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
                                    child: Text(
                                        "相册选取",
                                        style: TextStyle(color: Colors.white),
                                    ),
                                    onPressed: getImageGallery,
                                )
                            ),
                        )
                    ],
                ),
                Container(
                    padding: EdgeInsets.fromLTRB(20.0, 0, 20.0, 0),
                    child: Column(
                        children: <Widget>[
                            TextField(
                                // controller: _userName,
                                decoration: InputDecoration(
                                    labelText: "信息填写1",
                                    // hintText: "请输入信息1",
                                    prefixIcon: Icon(IconData(0xe699, fontFamily: "Iconfont"), size: 24.0)
                                ),
                            ),
                            TextField(
                                // controller: _passWord,
                                obscureText:true,
                                decoration: InputDecoration(
                                    labelText: "信息填写2",
                                    // hintText: "请输入信息1",
                                    prefixIcon: Icon(IconData(0xe699, fontFamily: "Iconfont"), size: 24.0)
                                ),
                            ),
                            TextField(
                                // controller: _passWord,
                                obscureText:true,
                                decoration: InputDecoration(
                                    labelText: "信息填写3",
                                    // hintText: "请输入信息3",
                                    prefixIcon: Icon(IconData(0xe699, fontFamily: "Iconfont"), size: 24.0)
                                ),
                            ),
                            TextField(
                                // controller: _passWord,
                                obscureText:true,
                                decoration: InputDecoration(
                                    labelText: "信息填写4",
                                    // hintText: "请输入信息4",
                                    prefixIcon: Icon(IconData(0xe699, fontFamily: "Iconfont"), size: 24.0)
                                ),
                            ),
                            TextField(
                                // controller: _passWord,
                                obscureText:true,
                                decoration: InputDecoration(
                                    labelText: "信息填写5",
                                    // hintText: "请输入信息5",
                                    prefixIcon: Icon(IconData(0xe699, fontFamily: "Iconfont"), size: 24.0)
                                ),
                            ),
                        ],
                    )
                )
              ],
          ),
      ),
    );
  }
}